package com.jhd.jiangxi;

import android.app.Application;
import android.content.SharedPreferences;

import androidx.fragment.app.FragmentManager;

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONArray;

import java.util.Map;

public class ScanApplication extends Application {
    private String accessToken;//访问令牌
    private String userId;
    private String userName;//登录用户名
    private String password;
    private String realName;//真实姓名
    private String deptId;//部门（单位）的Id
    private String deptName;//部门（单位）的名称
    private String entId;//阿里中的企业ID
    private String refEntId;//企业中的唯一ID
    private String backSystem = "1";//对接后台系统是正式库还是测试库.0-测试,1-正式
    private SharedPreferences.Editor userEditor;
    private String fromEntId;//供货单位的阿里id
    private String priceBookMstId;
    private String remark;
    private String sourceType;
    private String sourceId;
    private String fromEntName;//供货单位名称
    private String supplyDeptId; //免疫云系统中的供货单位ID
    private String supplyDeptId2; //免疫云系统中的供货单位ID
    private String supplyDeptName;
    private String receiveDeptId; //免疫规划云中的接收单位ID
    private String receiveDeptName;//免疫规划云中的接收单位名称
    private String priceIdIn;//价格本ID
    private String approvalIdIn;//审批流ID
    private String approvalIdOut;//审批流ID
    private String approvalCategoryIn;//审批类型(说明)
    private String approvalCategoryOut;//审批类型(说明)
    private String vaccineType;//疫苗类别 1-一类别，2-二类苗
    private String vaccineName;//疫苗类别 1-一类别，2-二类苗
    private String storageId;//储位编号
    private String storageId2;//储位编号
    private String storageName;//储位名称
    private String sheetInNo;// 扫单入库单
    private String sheetOutNo;//扫单出库单
    private String approvalId;//常规入库的审批流
    private String vaccinesType;//疫苗属性
    private String coldChainType;//运输设备的类型
    private String transformName;//运输单位
    private String transformId;//运输单位Id
    private String arrivalTime;//到达时间
    private String runTime;//起送时间
    private String saleDeptId;//下发单位Id
    private String saleDeptId2;//下发单位Id
    private String saleDeptName;//下发单位名称
    private  int position;
    //每次签收验货时，打开订单进入冷藏箱列表的时间，如果已有，并且是当天的时间，则沿用此时间作为开箱时间，如果不是当天的，则用当前时间保存一下
    //主要是为了解决冷藏箱中涉及多个运输单的疫苗，反复开箱后，当前温度异常的问题
    //内容是一个日期时间值,yyyy-MM-dd HH:mm:ss
    private String openBoxTime;
    private SharedPreferences.Editor billEditor;
    private String orderNoName;
    private SharedPreferences user;
    private SharedPreferences bill;
    private SharedPreferences login;
    private SharedPreferences.Editor loginEditor;
    protected SharedPreferences config;
    protected SharedPreferences.Editor configEditor;
    private String userPass;
    private String configDeptId;
    private String configDeptName;
    private String configPriceId;
    private String configPriceNo;
    private String configApprovalName;
    private String configApprovalId;
    private String configVaccineTypeId;
    private String configVaccineTypeName;
    private String configStorageName;
    private String configStorageId;
    private String priceNoIn;
    private String category;
    private String vaccineId;
    private String manufacturerId;
    private String propertyId;
    private String lotNumber;
    private String vaccineLots;
    private String checkType;
    private String checkVaccineType;
    private String deptType;
    private String refDeptId;

    public String getContractNo() {
        String s=bill.getString("contractNo",null);
        return s;
    }

    public void setContractNo(String contractNo) {
        billEditor.putString("contractNo", contractNo);
        billEditor.commit();
        this.contractNo = contractNo;
    }

    public String getDeptType() {
        String s=user.getString("deptType",null);
        return s;
    }

    public void setDeptType(String deptType) {
        userEditor.putString("deptType", deptType);
        userEditor.commit();
        this.deptType = deptType;
    }

    private String contractNo;

    public ScanApplication() {
    }

    public void setCheckVaccineType(String checkVaccineType) {
        billEditor.putString("checkVaccineType", checkVaccineType);
        billEditor.commit();
        this.checkVaccineType = checkVaccineType;
    }

    public String getCheckVaccineType() {
        String s=bill.getString("checkVaccineType",null);
        return s;
    }
    public void setCheckType(String checkType) {
        billEditor.putString("checkType", checkType);
        billEditor.commit();
        this.checkType = checkType;
    }

    public String getCheckType() {
        String s=bill.getString("checkType",null);
        return s;
    }

    public void isConfigEditor(){
         config = getSharedPreferences(getUserId(), MODE_PRIVATE);
         configEditor=config.edit();
    }

    public void setConfigDeptId(String configDeptId) {
        configEditor.putString("configDeptId", configDeptId);
        configEditor.commit();
        this.configDeptId = configDeptId;
    }
    public String getConfigDeptId() {
        String s=config.getString("configDeptId",null);
        return s;
    }
    public void setConfigDeptName(String configDeptName) {
        configEditor.putString("configDeptName", configDeptName);
        configEditor.commit();
        this.configDeptName = configDeptName;
    }
    public String getConfigDeptName() {
        String s=config.getString("configDeptName",null);
        return s;
    }
    public void setConfigPriceId(String configPriceId) {
        configEditor.putString("configPriceId", configPriceId);
        configEditor.commit();
        this.configPriceId = configPriceId;
    }
    public String getConfigPriceId() {
        String s=config.getString("configPriceId",null);
        return s;
    }
    public void setConfigPriceNo(String configPriceNo) {
        configEditor.putString("configPriceNo", configPriceNo);
        configEditor.commit();
        this.configPriceNo = configPriceNo;
    }
    public String getConfigPriceNo() {
        String s=config.getString("configPriceNo",null);
        return s;
    }
    public void setConfigApprovalName(String configApprovalName) {
        configEditor.putString("configApprovalName", configApprovalName);
        configEditor.commit();
        this.configApprovalName = configApprovalName;
    }
    public String getConfigApprovalName() {
        String s=config.getString("configApprovalName",null);
        return s;
    }
    public void setConfigApprovalId(String configApprovalId) {
        configEditor.putString("configApprovalId", configApprovalId);
        configEditor.commit();
        this.configApprovalId = configApprovalId;
    }
    public String getConfigApprovalId() {
        String s=config.getString("configApprovalId",null);
        return s;
    }
    public void setConfigVaccineTypeId(String configVaccineTypeId) {
        configEditor.putString("configVaccineTypeId", configVaccineTypeId);
        configEditor.commit();
        this.configVaccineTypeId = configVaccineTypeId;
    }
    public String getConfigVaccineTypeId() {
        String s=config.getString("configVaccineTypeId",null);
        return s;
    }
    public void setConfigVaccineTypeName(String configVaccineTypeName) {
        configEditor.putString("configVaccineTypeName", configVaccineTypeName);
        configEditor.commit();
        this.configVaccineTypeName = configVaccineTypeName;
    }
    public String getConfigVaccineTypeName() {
        String s=config.getString("configVaccineTypeName",null);
        return s;
    }
    public void setConfigStorageName(String configStorageName) {
        configEditor.putString("configStorageName", configStorageName);
        configEditor.commit();
        this.configStorageName = configStorageName;
    }
    public String getConfigStorageName() {
        String s=config.getString("configStorageName",null);
        return s;
    }
    public void setConfigStorageId(String configStorageId) {
        configEditor.putString("configStorageId", configStorageId);
        configEditor.commit();
        this.configStorageId = configStorageId;
    }
    public String getConfigStorageId() {
        String s=config.getString("configStorageId",null);
        return s;
    }




    public void setUserPass(String userPass) {
        loginEditor.putString("userPass", userPass);
        loginEditor.commit();
        this.userPass = userPass;
    }

    public String getUserPass() {
        String s=login.getString("userPass",null);
        return s;
    }

    public void setOrderNoName(String orderNoName) {
        billEditor.putString("orderNoName", orderNoName);
        billEditor.commit();
        this.orderNoName = orderNoName;
    }

    public void setOrderNoId(String orderNoId) {
        billEditor.putString("orderNoId", orderNoId);
        billEditor.commit();
        this.orderNoId = orderNoId;
    }
    public void setOrderNoId2(String orderNoId2) {
        billEditor.putString("orderNoId2", orderNoId2);
        billEditor.commit();
        this.orderNoId2 = orderNoId2;
    }

    public String getOrderNoName() {
        String s=bill.getString("orderNoName",null);
        return s;
    }


    public void setSaleDeptId(String saleDeptId) {
        billEditor.putString("saleDeptId", saleDeptId);
        billEditor.commit();
        this.saleDeptId = saleDeptId;
    }

    public String getSaleDeptId() {
        String s=bill.getString("saleDeptId",null);
        return s;
    }
    public void setSaleDeptId2(String saleDeptId2) {
        billEditor.putString("saleDeptId2", saleDeptId2);
        billEditor.commit();
        this.saleDeptId2 = saleDeptId2;
    }

    public String getSaleDeptId2() {
        String s=bill.getString("saleDeptId2",null);
        return s;
    }
    public void setRefDeptId(String refDeptId) {
        billEditor.putString("refDeptId", refDeptId);
        billEditor.commit();
        this.refDeptId = refDeptId;
    }

    public String getRefDeptId() {
        String s=bill.getString("refDeptId",null);
        return s;
    }
    public void setSaleDeptName(String saleDeptName) {
        billEditor.putString("saleDeptName", saleDeptName);
        billEditor.commit();
        this.saleDeptName = saleDeptName;
    }

    public String getSaleDeptName() {
        String s=bill.getString("saleDeptName",null);
        return s;
    }
    public void setLotNumber(String lotNumber) {
        billEditor.putString("lotNumber", lotNumber);
        billEditor.commit();
        this.lotNumber = lotNumber;
    }

    public String getLotNumber() {
        String s=bill.getString("lotNumber",null);
        return s;
    }
    public void setVaccineLots(String vaccineLots) {
        billEditor.putString("vaccineLots", vaccineLots);
        billEditor.commit();
        this.vaccineLots = vaccineLots;
    }

    public String getVaccineLots() {
        String s=bill.getString("vaccineLots",null);
        return s;
    }
    public void setCategory(String category) {
        billEditor.putString("category", category);
        billEditor.commit();
        this.category = category;
    }

    public String getCategory() {
        String s=bill.getString("category",null);
        return s;
    }
    public void setManufacturerId(String manufacturerId) {
        billEditor.putString("manufacturerId", manufacturerId);
        billEditor.commit();
        this.manufacturerId = manufacturerId;
    }

    public String getManufacturerId() {
        String s=bill.getString("manufacturerId",null);
        return s;
    }
    public void setVaccineId(String vaccineId) {
        billEditor.putString("vaccineId", vaccineId);
        billEditor.commit();
        this.vaccineId = vaccineId;
    }

    public String getVaccineId() {
        String s=bill.getString("vaccineId",null);
        return s;
    }


    public void setColdChainType(String coldChainType) {
        billEditor.putString("coldChainType", coldChainType);
        billEditor.commit();
        this.coldChainType = coldChainType;
    }

    public String getColdChainType() {
        String s=bill.getString("coldChainType",null);
        return s;
    }
    public void setArrivalTime(String arrivalTime) {
        billEditor.putString("arrivalTime", arrivalTime);
        billEditor.commit();
        this.arrivalTime = arrivalTime;
    }

    public String getArrivalTime() {
        String s=bill.getString("arrivalTime",null);
        return s;
    }
    public void setRunTime(String runTime) {
        billEditor.putString("runTime", runTime);
        billEditor.commit();
        this.runTime = runTime;
    }

    public String getRunTime() {
        String s=bill.getString("runTime",null);
        return s;
    }
    public void setTransformName(String transformName) {
        billEditor.putString("transformName", transformName);
        billEditor.commit();
        this.transformName = transformName;
    }

    public String getTransformName() {
        String s=bill.getString("transformName",null);
        return s;
    }
    public void setTransformId(String transformId) {
        billEditor.putString("transformId", transformId);
        billEditor.commit();
        this.transformId = transformId;
    }

    public String getTransformId() {
        String s=bill.getString("transformId",null);
        return s;
    }

    public void setVaccinesType(String vaccinesType) {
        billEditor.putString("vaccinesType", vaccinesType);
        billEditor.commit();
        this.vaccinesType = vaccinesType;
    }

    public String getVaccinesType() {
        String s=bill.getString("vaccinesType",null);
        return s;
    }
    public void setSheetInNo(String sheetInNo) {
        billEditor.putString("sheetInNo", sheetInNo);
        billEditor.commit();
        this.sheetInNo = sheetInNo;
    }
    public String getApprovalId() {
        String s=bill.getString("approvalId",null);
        return s;
    }
    public void setApprovalId(String approvalId) {
        billEditor.putString("approvalId", approvalId);
        billEditor.commit();
        this.approvalId = approvalId;
    }

    public String getSheetInNo() {
        String s=bill.getString("sheetInNo",null);
        return s;
    }
    public void setRemark(String remark) {
        billEditor.putString("remark", remark);
        billEditor.commit();
        this.remark = remark;
    }

    public String getRemark() {
        String s=bill.getString("remark",null);
        return s;
    }
    public void setPropertyId(String propertyId) {
        billEditor.putString("propertyId", propertyId);
        billEditor.commit();
        this.propertyId = propertyId;
    }

    public String getPropertyId() {
        String s=bill.getString("propertyId",null);
        return s;
    }
    public void setSourceType(String sourceType) {
        billEditor.putString("sourceType", sourceType);
        billEditor.commit();
        this.sourceType = sourceType;
    }

    public String getSourceType() {
        return sourceType;
    }
    public void setSourceId(String sourceId) {
        billEditor.putString("sourceId", sourceId);
        billEditor.commit();
        this.sourceId = sourceId;
    }

    public String getSourceId() {
        return sourceId;
    }
    public void setPriceBookMstId(String priceBookMstId) {
        billEditor.putString("priceBookMstId", priceBookMstId);
        billEditor.commit();
        this.priceBookMstId = priceBookMstId;
    }

    public String getPriceBookMstId() {
        String s=bill.getString("priceBookMstId",null);
        return s;
    }

    public String getOrderNoId() {
        String s=bill.getString("orderNoId",null);
        return s;
    }public String getOrderNoId2() {
        String s=bill.getString("orderNoId2",null);
        return s;
    }

    private String orderNoId;
    private String orderNoId2;

    @Override
    public void onCreate() {
        super.onCreate();
        //为应用设置异常处理,然后程序才能获取未处理的异常
        CrashHandler crashHandler = CrashHandler.getsInstance();
        crashHandler.init(this);
        user = getSharedPreferences(UtilHelper.Cache.USER, MODE_PRIVATE);
        userEditor=user.edit();
        bill = getSharedPreferences(UtilHelper.Cache.BILL, MODE_PRIVATE);
        billEditor=bill.edit();
        login = getSharedPreferences(UtilHelper.Cache.LOGIN, MODE_PRIVATE);
        loginEditor=login.edit();
        config = getSharedPreferences(userId, MODE_PRIVATE);
        configEditor=config.edit();
    }

    public String getAccessToken() {
        String s="Bearer " +user.getString("accessToken",null);
        return s;
    }

    public void setAccessToken(String accessToken) {
        userEditor.putString("accessToken", accessToken);
        userEditor.commit();
        this.accessToken = accessToken;
    }

    public String getUserId() {
        String s=user.getString("userId",null);
        return s;
    }

    public void setUserId(String userId) {
        userEditor.putString("userId", userId);
        userEditor.commit();
        this.userId = userId;
    }

    public String getUserName() {
        String s=user.getString("userName",null);
        return s;
    }

    public void setUserName(String userName) {
        userEditor.putString("userName", userName);
        userEditor.commit();
        this.userName = userName;
    }

    public String getRealName() {
        String s=user.getString("realName",null);
        return s;
    }

    public void setRealName(String realName) {
        userEditor.putString("realName", realName);
        userEditor.commit();
        this.realName = realName;
    }

    public String getDeptId() {
        String s=user.getString("deptId",null);
        return s;
    }

    public void setDeptId(String deptId) {
        userEditor.putString("deptId", deptId);
        userEditor.commit();
        this.deptId = deptId;
    }

    public String getDeptName() {
        String s=user.getString("deptName",null);
        return s;
    }

    public void setDeptName(String deptName) {
        userEditor.putString("deptName", deptName);
        userEditor.commit();
        this.deptName = deptName;
    }

    public String getPassword() {
        String s=user.getString("password",null);
        return s;
    }

    public void setPassword(String password) {
        userEditor.putString("password", password);
        userEditor.commit();
        this.password = password;
    }

    public String getEntId() {
        String s=user.getString("entId",null);
        return s;
    }

    public void setEntId(String entId) {
        userEditor.putString("entId", entId);
        userEditor.commit();
        this.entId = entId;
    }

    public String getRefEntId() {
        String s=user.getString("refEntId",null);
        return s;
    }

    public void setRefEntId(String refEntId) {
        userEditor.putString("refEntId", refEntId);
        userEditor.commit();
        this.refEntId = refEntId;
    }

    public String getBackSystem() {
        String s=config.getString("backSystem","1");
        return s;
    }

    public void setBackSystem(String backSystem) {
        configEditor.putString("backSystem", backSystem);
        configEditor.commit();
        this.backSystem = backSystem;
    }


    public String getFromEntId() {
        String s=bill.getString("fromEntId",null);
        return s;
    }

    public void setFromEntId(String fromEntId) {
        billEditor.putString("fromEntId", fromEntId);
        billEditor.commit();
        this.fromEntId = fromEntId;
    }

    public String getFromEntName() {
        String s=bill.getString("fromEntName",null);
        return s;
    }

    public void setFromEntName(String fromEntName) {
        billEditor.putString("fromEntName", fromEntName);
        billEditor.commit();
        this.fromEntName = fromEntName;
    }

    public String getSupplyDeptId() {
        String s=bill.getString("supplyDeptId",null);
        return s;
    }

    public void setSupplyDeptId(String supplyDeptId) {
        billEditor.putString("supplyDeptId", supplyDeptId);
        billEditor.commit();
        this.supplyDeptId = supplyDeptId;
    }
    public String getSupplyDeptId2() {
        String s=bill.getString("supplyDeptId2",null);
        return s;
    }

    public void setSupplyDeptId2(String supplyDeptId2) {
        billEditor.putString("supplyDeptId2", supplyDeptId2);
        billEditor.commit();
        this.supplyDeptId2 = supplyDeptId2;
    }

    public String getSupplyDeptName() {
        String s=bill.getString("supplyDeptName",null);
        return s;
    }

    public void setSupplyDeptName(String supplyDeptName) {
        billEditor.putString("supplyDeptName", supplyDeptName);
        billEditor.commit();
        this.supplyDeptName = supplyDeptName;
    }

    public String getReceiveDeptId() {
        String s=bill.getString("receiveDeptId",null);
        return s;
    }

    public void setReceiveDeptId(String receiveDeptId) {
        billEditor.putString("receiveDeptId", receiveDeptId);
        billEditor.commit();
        this.receiveDeptId = receiveDeptId;
    }

    public String getReceiveDeptName() {
        String s=bill.getString("receiveDeptName",null);
        return s;
    }

    public void setReceiveDeptName(String receiveDeptName) {
        billEditor.putString("receiveDeptName", receiveDeptName);
        billEditor.commit();
        this.receiveDeptName = receiveDeptName;
    }

    public String getPriceIdIn() {
        String s=bill.getString("priceIdIn",null);
        return s;
    }

    public void setPriceIdIn(String priceIdIn) {
        billEditor.putString("priceIdIn", priceIdIn);
        billEditor.commit();
        this.priceIdIn = priceIdIn;
    }

    public String getPriceNoIn() {
        String s=bill.getString("priceNoIn",null);
        return s;
    }

    public void setPriceNoIn(String priceNoIn) {
        billEditor.putString("priceNoIn", priceNoIn);
        billEditor.commit();
        this.priceNoIn = priceNoIn;
    }

    public int getPosition() {
        int s=bill.getInt("position",0);
        return s;
    }

    public void setPosition(int position) {
        billEditor.putInt("position", position);
        billEditor.commit();
        this.position = position;
    }

    public String getApprovalIdIn() {
        String s=bill.getString("approvalIdIn",null);
        return s;
    }

    public void setApprovalIdIn(String approvalIdIn) {
        billEditor.putString("approvalIdIn", approvalIdIn);
        billEditor.commit();
        this.approvalIdIn = approvalIdIn;
    }

    public String getApprovalIdOut() {
        String s=bill.getString("approvalIdOut",null);
        return s;
    }

    public void setApprovalIdOut(String approvalIdOut) {
        billEditor.putString("approvalIdOut", approvalIdOut);
        billEditor.commit();
        this.approvalIdOut = approvalIdOut;
    }

    public String getApprovalCategoryIn() {
        String s=bill.getString("approvalCategoryIn",null);
        return s;
    }

    public void setApprovalCategoryIn(String approvalCategoryIn) {
        billEditor.putString("approvalCategoryIn", approvalCategoryIn);
        billEditor.commit();
        this.approvalCategoryIn = approvalCategoryIn;
    }


    public String getVaccineType() {
        String s=bill.getString("vaccineType",null);
        return s;
    }

    public void setVaccineType(String vaccineType) {
        billEditor.putString("vaccineType", vaccineType);
        billEditor.commit();
        this.vaccineType = vaccineType;
    }
    public String getVaccineName() {
        String s=bill.getString("vaccineName",null);
        return s;
    }

    public void setVaccineName(String vaccineName) {
        billEditor.putString("vaccineName", vaccineName);
        billEditor.commit();
        this.vaccineName = vaccineName;
    }

    public String getStorageId() {
        String s=bill.getString("storageId",null);
        return s;
    }

    public void setStorageId(String storageId) {
        billEditor.putString("storageId", storageId);
        billEditor.commit();
        this.storageId = storageId;
    }
    public String getStorageId2() {
        String s=bill.getString("storageId2",null);
        return s;
    }

    public void setStorageId2(String storageId2) {
        billEditor.putString("storageId2", storageId2);
        billEditor.commit();
        this.storageId2 = storageId2;
    }

    public String getStorageName() {
        String s=bill.getString("storageName",null);
        return s;
    }

    public void setStorageName(String storageName) {
        billEditor.putString("storageName", storageName);
        billEditor.commit();
        this.storageName = storageName;
    }

    public String getOpenBoxTime() {
        String s=bill.getString("openBoxTime",null);
        return s;
    }

    public void setOpenBoxTime(String openBoxTime) {
        billEditor.putString("openBoxTime", openBoxTime);
        billEditor.commit();
        this.openBoxTime = openBoxTime;
    }


    public JSONArray getStorageList() {
        SharedPreferences bill = getSharedPreferences(UtilHelper.Cache.BILL, MODE_PRIVATE);
        String storages = bill.getString("storageList", null);
        if (storages == null) return null;
        return JSON.parseArray(storages);
    }

    public void setStorageList(JSONArray s) {
        if (s == null) billEditor.remove("storageList");
        else billEditor.putString("storageList", JSONArray.toJSONString(s));
        billEditor.commit();
    }

    public JSONArray getDeliveryDepts() {
        SharedPreferences bill = getSharedPreferences(UtilHelper.Cache.BILL, MODE_PRIVATE);
        String supplyDept = bill.getString("deliveryDepts", null);
        if (supplyDept == null) return null;
        return JSON.parseArray(supplyDept);
    }
    public String getReason(String reason) {
        if("01".equals(reason)){
            return "包装无法识别";
        }else if("02".equals(reason)){
            return "超过有效期";
        }else if("03".equals(reason)){
            return "不符合储存温度要求";
        }else if("09".equals(reason)){
            return "其他";
        }
        return "未选择";
    }

    public void setDeliveryDtl(JSONArray s) {
        if (s == null) billEditor.remove("DeliveryDtl");
        else billEditor.putString("DeliveryDtl", JSONArray.toJSONString(s));
        billEditor.commit();
    }

    public JSONArray getDeliveryDtl() {
        SharedPreferences bill = getSharedPreferences(UtilHelper.Cache.BILL, MODE_PRIVATE);
        String supplyDept = bill.getString("DeliveryDtl", null);
        if (supplyDept == null) return null;
        return JSON.parseArray(supplyDept);
    }

    public void setDeliveryDepts(JSONArray s) {
        if (s == null) billEditor.remove("deliveryDepts");
        else billEditor.putString("deliveryDepts", JSONArray.toJSONString(s));
        billEditor.commit();
    }

    public void clearBill(){
        billEditor.clear();
        billEditor.commit();
        String ss=this.checkType;
    }

    public void clearAll() {
        billEditor.clear();
        billEditor.commit();
        userEditor.clear();
        userEditor.commit();
    }




}
